package com.jswlw.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class SnUtils {

    private static long orderNum = 0l;
    private static long taskNum = 0l;
    private static long roomNum = 0l;
    private static String date;

    /**
     * 生成订单编号
     *
     * @return
     */
    public static synchronized String getOrderNo() {
        String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());
        if (date == null || !date.equals(str)) {
            date = str;
            orderNum = 0l;
        }
        orderNum++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += orderNum;
        return orderNo + "";
    }

    /**
     * 生成订单编号
     *
     * @return
     */
    public static synchronized String getTaskNo() {
        String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());
        if (date == null || !date.equals(str)) {
            date = str;
            orderNum = 0l;
        }
        taskNum++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += taskNum;
        return "T" + orderNo + "";
    }

    /**
     * 生成订单编号
     *
     * @return
     */
    public static synchronized String getNoticeNo() {
        String str = new SimpleDateFormat("yyMMddHHmm").format(new Date());
        if (date == null || !date.equals(str)) {
            date = str;
            orderNum = 0l;
        }
        taskNum++;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += taskNum;
        return "N" + orderNo + "";
    }


    public static String getRoomNo() {
        int length=6;
        String result = "";
        Random rand = new Random();

        int randInt = 0;
        for (int i = 0; i < length; i++) {
            randInt = rand.nextInt(10);

            result += randInt;
        }
        return result;
    }
    public static void main(String[] args){

        String sn=SnUtils.getRoomNo();
        System.out.println(sn);
        sn=SnUtils.getRoomNo();
        System.out.println(sn);
    }
}
